<!DOCTYPE html>
<html class="x-admin-sm">
    
    <head>
        <meta charset="UTF-8">
        <title>管理员管理页面</title>
        <meta name="renderer" content="webkit">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
        <link rel="stylesheet" href="../../public/css/font.css">
        <link rel="stylesheet" href="../../public/css/xadmin.css">
        <script type="text/javascript" src="../../public/lib/layui/layui.js" charset="utf-8"></script>
        <script type="text/javascript" src="../../public/js/xadmin.js"></script>
        <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
        <!--[if lt IE 9]>
            <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
            <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
        <![endif]-->
    </head>
    <body>
        <div class="layui-fluid">
            <div class="layui-row">
                <form class="layui-form">
                  <div class="layui-form-item">
                      <label for="namecode" class="layui-form-label">
                          <span class="x-red">*</span>学号
                      </label>
                      <div class="layui-input-inline">
                          <input type="text" id="namecode" name="namecode" required="" lay-verify="required"
                          autocomplete="off" class="layui-input" value="{{.um.Namecode}}">
                      </div>
                      <div class="layui-form-mid layui-word-aux">
                          <span class="x-red">*</span>唯一的登入名
                      </div>
                  </div>
                  <div class="layui-form-item">
                      <label for="username" class="layui-form-label">
                          <span class="x-red">*</span>姓名
                      </label>
                      <div class="layui-input-inline">
                          <input type="text" id="username" name="username" required="" lay-verify="required"
                          autocomplete="off" class="layui-input" value="{{.um.Username}}">
                      </div>
                      <div class="layui-form-mid layui-word-aux">
                          <span class="x-red">*</span>真实姓名
                      </div>
                  </div>
                  <div class="layui-form-item">
                      <label class="layui-form-label"><span class="x-red">*</span>角色</label>
                      <div class="layui-input-inline">
                        <!-- <select name="contrller">
                            <option{{if eq .um.Role 1}} selected{{end}}>超级管理员</option>
                            <option{{if eq .um.Role 2}} selected{{end}}>操作员</option>
                            <option{{if eq .um.Role 3}} selected{{end}}>普通用户</option>
                        </select> -->
                      <!-- layui用select在火狐这里不兼容 -->
                        <input name="role" value="1"{{if eq .um.Role 1}} checked{{end}} type="radio" title="超级管理员" disabled>
                        <input name="role" value="2"{{if eq .um.Role 2}} checked{{end}} type="radio" title="操作员">
                        <input name="role" value="3"{{if eq .um.Role 3}} checked{{end}} type="radio" title="普通用户">
                      </div>
                  </div>
                  <div class="layui-form-item">
                      <label for="L_pass" class="layui-form-label">
                          密码
                      </label>
                      <div class="layui-input-inline">
                          <input type="password" id="L_pass" name="psw1" lay-verify="psw1"
                          autocomplete="off" class="layui-input">
                      </div>
                      <div class="layui-form-mid layui-word-aux">
                          5到15个字符
                      </div>
                  </div>
                  <div class="layui-form-item">
                      <label for="L_repass" class="layui-form-label">
                          确认密码
                      </label>
                      <div class="layui-input-inline">
                          <input type="password" id="L_repass" name="psw2" lay-verify="psw2"
                          autocomplete="off" class="layui-input">
                      </div>
                  </div>
                  <div class="layui-form-item">
                      <label for="L_repass" class="layui-form-label">
                      </label>
                      <button  class="layui-btn" lay-filter="add" lay-submit="">
                          修改
                      </button>
                  </div>
              </form>
            </div>
        </div>
        <script src="https://cdn.bootcdn.net/ajax/libs/jsencrypt/3.0.0-rc.1/jsencrypt.js"></script>
        <script>
        var PUBLIC_KEY = '{{.pubkey}}';
        var encrypt = new JSEncrypt();
        encrypt.setPublicKey('-----BEGIN PUBLIC KEY-----'+PUBLIC_KEY+'-----END PUBLIC KEY-----');
        layui.use(['form', 'layer'],
            function() {
                $ = layui.jquery;
                var form = layui.form,
                layer = layui.layer;

                //自定义验证规则
                form.verify({
                    namecode: function(value) {
                        if (value.length < 5 || value.length > 10) {
                            return '学号范围5-10个字符';
                        }
                    },
                    psw1: function(value) {
                        if (value.length != 0 && (value.length < 5 || value.length > 15)) {
                            return '密码必须5到15位';
                        }
                    },
                    psw2: function(value) {
                        if ($('#L_pass').val() != $('#L_repass').val()) {
                            return '两次密码不一致';
                        }
                    }
                });

                //监听提交
                form.on('submit(add)',
                function(data) {
                    console.log(data);
                    //发异步，把数据提交给php
                    $.ajax({
                        url: "./edit",
                        type: "post",
                        data: {data: encrypt.encrypt(JSON.stringify({
                            id:{{.um.Id}},
                            namecode: data.field.namecode,
                            username: data.field.username,
                            password: data.field.psw1,
                            role: Number(data.field.role),
                        }))},
                        dataType: "json",
                        success: function (resp) {
                            console.log(resp);
                            if (resp.status) {
                                layer.alert("修改成功", {icon:6},
                                    function() {
                                        //关闭当前frame
                                        xadmin.close();
                                        // 可以对父窗口进行刷新 
                                        // xadmin.father_reload();
                                    }
                                );
                            } else {
                                layer.alert("修改失败", {icon:2});
                            }
                        }
                    });
                    return false;
                });

            });</script>
        <script>var _hmt = _hmt || []; (function() {
                var hm = document.createElement("script");
                hm.src = "https://hm.baidu.com/hm.js?b393d153aeb26b46e9431fabaf0f6190";
                var s = document.getElementsByTagName("script")[0];
                s.parentNode.insertBefore(hm, s);
            })();</script>
    </body>

</html>
